<?php

/**
* @Author:  	Daniel Dinh
* @Email:   	webdevelopmentvn@gmail.com
* @Link: 		http://joomsoft.net
* @Version: 	1.0
* @copyright:	Joomsoft.net
* @license:		GNU GPL v3
*/


defined('_JEXEC') or die;

class importimgHelper
{

	public static function addSubmenu($vName)
	{
		JSubMenuHelper::addEntry(
			JText::_('COM_IMPORTIMG_SUBMENU_IMPORTIMG'),
			'index.php?option=com_importimg&view=importimg',
			$vName == 'importimg'
		);
	

	}
	/**
	 * Gets a list of the actions that can be performed.
	 * @return	JObject
	 * @since	1.6
	 */

	public static function getActions()
	{
		$user	= JFactory::getUser();
		$result	= new JObject;
		$assetName = 'com_importimg';
		$actions = array(
			'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.state', 'core.delete'
		);
		foreach ($actions as $action) {
			$result->set($action,	$user->authorise($action, $assetName));

		}
		return $result;

	}
	function quickIconButton( $link, $image, $text ) {
		
		$lang	= &JFactory::getLanguage();
		$button = '';
		$button .= '<div class="icon-wrapper">';
		$button .=	'<div class="icon">'
				   .'<a href="'.$link.'">'
				   .JHTML::_('image', 'administrator/components/com_importimg/assets/images/'.$image, $text )
				   .'<span>'.$text.'</span></a>'
				   .'</div>';
		$button .= '</div>';
		return $button;
	}


	public function post_curl($url) 
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
		$result = curl_exec($ch);
		curl_close ($ch);
		return $result;

	}

	public function get_curl($url) 
	{
	    $ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_GET, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
		$result = curl_exec($ch);
		curl_close ($ch);
	    return $result;
	}
	
	public function get_image_curl($url)
	{
		$ch = curl_init ($url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
		$rawdata=curl_exec($ch);
		return $rawdata;
	}
	
	public function getMidPath($file)
	{
		$filename = basename($file);
		$temp = str_replace('http://','',$file);
		for($t=0;$t<strlen($temp);$t++)
		{
			if($temp[$t]=="/")
			{
				$index = $t;
				break;
			}
		}
		$tem_mid_path = substr($temp,$t,strlen($temp) - $t);
		$temp_path = str_replace($filename,'',$tem_mid_path);
		$newpaths = @explode("/",$temp_path);		
		$respath = array();
		if($newpaths)
		{
			foreach($newpaths as $tp)
				if($tp)	
					$respath[] = $tp;
		}
		return $respath;
	}
}

